<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>HUI 用户注册界面</title>
<link rel="stylesheet" type="text/css" href="css/hui.css" />
</head>
<body style="background:#F4F5F6;">
<header class="hui-header">
    <div id="hui-back"></div>
    <h1>用户注册</h1>
</header>
<div class="hui-wrap">
    <div class="hui-center-title" style="margin-top:35px;"><h1 style="border:0px;">公司logo位置</h1></div>
    <div style="margin:28px; margin-bottom:15px;" class="hui-form" id="form1">
        <div class="hui-form-items">
            <input id="phoneNum" type="text" class="hui-input hui-input-clear" placeholder="手机号码" checkType="phone" checkMsg="手机号码格式错误" />
        </div>
        <div class="hui-form-items">
            <input id="pwd" type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checkType="string" id="pwd" checkData="6,20" checkMsg="密码应为6-20个字符" />
        </div>
        <div class="hui-form-items">
            <input type="password" class="hui-input hui-pwd-eye" placeholder="确认密码" checkType="sameWithId" checkData="pwd" checkMsg="两次密码不一致"  />
        </div>
        <div class="hui-form-items">
            <input id="msgCode" type="text" style="width: 70%;" class="hui-fl hui-input" placeholder="短信验证码"/>
            <a id="send" class="hui-rl" href="javascript:send()">
            	<spanstyle="color: #188EEE;font-size: 15px;">发送验证码</span>
            </a>
            <a id="send2" class="hui-rl" style="display: none;">
            	<spanstyle="color: #188EEE;font-size: 15px;">已发送</span> 
            </a>
        </div>
    </div>
    <div style="padding:28px; padding-top:0px;">
        <button type="button" class="hui-button hui-button-large hui-primary" id="submit">立即注册</button>
    </div>
</div>
<script type="text/javascript" src="js/hui.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/jquery.min.js" charset="UTF-8"></script>
<script src="js/hui-form.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	function chinese(data){
	return encodeURI(encodeURI(data));
}
hui('#submit').click(function(){
	
    //验证
    var res = huiFormCheck('#form1');
    //提交
    if(res){
    	var code = $("#msgCode").val();
    	var phone = $("#phoneNum").val();
    	var pass = $("#pwd").val();
    	
    	if(code==""){
    		hui.toast("请填写短信验证码");return;
    	}
		hui.loading('数据处理中');
    	hui.post(
		    url_root+':8080/st/servlet/UserServlet',
		    {method:'userReg', phone:phone,pass:pass,code:code},
		    function(msg){
		    	if(msg=='exist'){
		    		hui.alert('手机号码已经存在！','好的', function(){
		    			hui.loading(false, true);
		    		});
		    	}
		    	else if(msg=='codeError'){
		    		hui.alert('短信验证码错误！','好的', function(){
		    			hui.loading(false, true);
		    		});
		    	}
		    	else
		    	{
		    		hui.loading(false, true);
		    		localStorage.setItem("nowUser",msg);
		    		hui.alert('注册成功！','好的', function(){
		    			 hui.open('yonghu.html');
		    		});
		    	}
		    },
		    function(e){
		        hui.iconToast('网络故障', 'warn');
		    }
		);
    	
    	//hui.iconToast('验证通过！');
    }
});
function send(){//
	var res = huiFormCheck('#form1');
	if(res){
	$("#send").hide();
	hui.post(
	    url_root+':8080/st/servlet/MsgServlet',
	    {method:'send', phone:hui("#phoneNum").val(),reason:'reg'},
	    function(msg){
	    	if(msg=="success")
	        hui.upToast("发送成功,60秒后可重新发送。");
	        $("#send2").show();
	        setTimeout(function(){//两秒后跳转  
	                  $("#send2").hide();
	                  $("#send").show();
	                },60000);
	    },
	    function(e){
	        hui.iconToast('网络故障', 'warn');
	    }
	);
	}
}
</script>
</body>
</html>